Skip to content

feat: publish a package template from its producers' releases - #4

Merged
showxu merged 5 commits into
masterfrom
feat/template-publisher
Oct 24, 2026
Merged

showxu merged 5 commits into
masterfrom
feat/template-publisher

Conversation

@showxu

@showxu showxu commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Change

scripts/publish-template.py publishes a template repository's generated files from their producers' releases, as declared by a template-composition JSON block in the declaration repository's MAINTENANCE.md (swift-library/.github#45 adds the block for swift-package-template). For each producer it clones the highest vMAJOR.MINOR.PATCH tag, runs that producer's generators into empty directories, requires the generated files to be exactly the declared ones, and writes only the declared template paths. When anything changed, it commits signed on chore/publish-<digest>, pushes, opens one pull request listing each producer's release, commit and changed files, and requests a squash auto-merge of that head when the template allows auto-merge. --write-only stops after writing the files.

The README's new "Package template publication" section documents the declaration format and the run. Tests use local producer, template and declaration repositories, real SSH-signed commits and a stub gh.

Decisions

  • One release per producer repository. Every generator from one repository runs from the same release checkout. "Latest release" is the highest vMAJOR.MINOR.PATCH tag without a pre-release suffix: none of these repositories publishes GitHub Releases, only tags.
  • Declared output set. A generator that produces an undeclared file or misses a declared one fails the run before anything is written. A profile that gains or loses files therefore needs a declaration change first.
  • Skeleton untouched. Only declared paths are written. Package.swift, Sources, Tests, VERSION and CHANGELOG.md are not declared.
  • Preconditions. Both checkouts must be clean. Every URL the template's origin fetches from or pushes to, after Git's URL rewriting, must name the declared template on GitHub, and a publishing run starts from both default-branch heads.
  • Starting over. The branch name comes from the declaration commit and the producer commits. A publishing run stops before writing anything if that branch already exists, locally or on origin. A failed push or pull request prints the git -C <template> commands that delete the branch, and the same command then publishes again from the default branch head, so the script only ever pushes the commit it just created. A failed auto-merge request leaves the open pull request to merge by hand.
  • Paths. Declared paths must be normalized and relative. They must not name Git metadata, and must not repeat or nest in one another, ignoring letter case. Every existing ancestor must be a directory and no path may cross a symbolic link, all checked before any file is written.
  • No workflow yet. Opening a pull request in another repository needs an App credential. The organization's only App is the review connector, whose credentials live outside GitHub, and no Actions secrets exist. The minimal version is therefore the same command, run by a maintainer with their own credentials after each producer release.
  • Auto-merge. swift-package-template has allow_auto_merge: false, so a run leaves the pull request for a manual merge after the required checks pass. Enabling it is a settings change for the owner.

Validation

  • python3 -m unittest discover -s tests: 142 tests pass, 22 of them for the publisher. The tests serve git@github.com: URLs from local bare repositories through a stub ssh, so the GitHub-only origin check runs as in production. After each injected failure, the tests run the printed commands from outside the template checkout and publish again. actionlint passes.
  • Independent review, Astra High, read-only:
    • Round 1 raised four should-fix findings: the push URL was not validated, .GIT case variants passed, nested or file-ancestor destinations passed, and interrupted runs could not be completed.
    • Round 2 confirmed the .GIT fix and raised three more: URL rewriting could redirect origin, case-variant destinations still collided, and the recovery commands were directory-dependent and lost the PR description.
    • Round 3 found that resuming could push changes outside the declared paths. 65aec6a removes resuming: a failed run starts over from the default branch head.
    • Round 4 found that a network outage could hide the recovery commands. 4faabed builds them from where the failure happened, without contacting origin.
    • Fixed in 85dfec1, e472aca, 65aec6a and 4faabed. Each finding's tests fail against the commit before its fix.
  • End to end with the real composition from docs: declare the package template's composition .github#45, local mirrors of the two producers, and scratch tags standing in for releases:

Release-relevant

swift-library/skills' latest tag, v0.1.0, predates export_profile.py, so the first real publication needs a skills release that contains it. showxu/skills v0.1.2 already reproduces the template's logo byte for byte.

scripts/publish-template.py reads the template composition that a
declaration repository's MAINTENANCE.md declares, clones each producer's
highest vMAJOR.MINOR.PATCH release, runs its generators into empty
directories and writes the declared template paths. When files change, it
commits them signed on one branch, opens one pull request listing each
release, and requests auto-merge where the template allows it.

The unit suite runs it against local producer, template and declaration
repositories. No workflow calls it yet; a maintainer runs it after each
producer release until an App credential can open pull requests.
The publisher requires origin to name the declared template on GitHub and to
push where it fetches, rejects Git metadata paths in any letter case, nested
declared files and file ancestors before writing, and stops before writing
when the publication branch already exists. A failed push, pull request or
auto-merge request reports the command that completes it.
The publisher checks every effective fetch and push URL of the template's
origin, after Git's URL rewriting, against the declared repository on
GitHub, and rejects declared paths that collide or nest when letter case is
ignored. A failed push, pull request or auto-merge request now asks for the
same command again: the rerun resumes from the publication branch in the
checkout or on origin when that branch builds on the current default head
and holds the current releases' output, keeping the pull request's
description.
A publishing run stops before writing when its publication branch exists.
A failed push or pull request prints the git -C commands that delete the
branch, after which the same command publishes again from the default
branch head, so the script only ever pushes the commit it just created. A
failed auto-merge request leaves the open pull request.
The recovery after a failed push or pull request is built from where the failure happened instead of another ls-remote, so an outage that fails the push still prints the original error and the commands that delete the publication branch.
@showxu
showxu merged commit 75929f1 into master Oct 24, 2026
51 checks passed
@showxu
showxu deleted the feat/template-publisher branch October 24, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant